#include "myTasks.h"
#include <QDebug>

void AxisAdjust::doAdjust(const QList<qreal> &data)
{
qDebug() << "doAdjust Thread working";
    if(data.size() != 5){
        qDebug() << "doAdjust() error";
        return;
    }
    QList<qreal> ampList;
    //这里没考虑三图横坐标范围不同的情况，这里以AX横坐标为准
    int size = numVis[0].size();
    qreal cap = data[3];//(axis_tx->max()-axis_tx->min())/step
    for(int i = 0; i < 3; ++i){
        //插入新值
        numVis[i].push_back(data[i]);
        hashMap[i][data[i]]++;
        if(size > cap){
            hashMap[i][numVis[i].front()]--;
            if(hashMap[i][numVis[i].front()] == 0)
                hashMap[i].remove(numVis[i].front());
            numVis[i].pop_front();
        }
        //如果不需要显示全部，输出当前区域最值
        if(data[4] == 0){
            auto itBeg = hashMap[i].begin().key();
            auto itEnd = (hashMap[i].end()-1).key();
            itBeg = itBeg > 0 ? (0.9*itBeg > 0.01 ? 0.9*itBeg : 0.01) : (1.1*itBeg < -0.01 ? 1.1*itBeg : -0.01);
            itEnd = itEnd > 0 ? (1.1*itEnd > 0.01 ? 1.1*itEnd : 0.01): (0.9*itEnd < -0.01 ? 0.9*itEnd : -0.01);
            ampList.push_back(itBeg);
            ampList.push_back(itEnd);
        }
        //更新全域最值
        if(data[i] < extremList[2*i]) extremList[2*i] = data[i];
        if(data[i] > extremList[2*i+1]) extremList[2*i+1] = data[i];
    }
    emit resultReady( data[4] ? extremList : ampList );
}




